class Solution {
public:
    vector<int> sortedSquares(vector<int>& nums) {
        vector<int>n(nums.size(),0);
        int k = nums.size()-1;

        int left = 0,right = k;
        while(left <= right){
            int s1 = nums[left]*nums[left];
            int s2 = nums[right]*nums[right];

            if(s1 > s2){
                n[k--]= s1;
                left++;
            }
            else{
                n[k--]= s2;
                right--;
            }

        }

        return n;
    }
};

